<!DOCTYPE html>
<html>

<head>
    <title>5W点的大围栏编辑</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body,
        html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #allmap {
            width: 100%;
            height: 100%;
        }

        p {
            margin-left: 5px;
            font-size: 14px;
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=U3q69k0Dv0GCYNiiZeHPf7BS"></script>
    <script src="../dist/inmap.js"></script>
    <script src="./data/neimengGeo.js"></script>
</head>

<body>
    <div id="allmap"></div>
    <div style="position: fixed;top: 0;width: 100%">
        <button onclick="addOverlay()"> 创建围栏</button>
        <button onclick="addEditorOverLay()">创建一个可编辑围栏</button>
        <button onclick="openEdit()"> 打开编辑</button>
        <button onclick="closeEdit()">关闭编辑</button>
        <button onclick="translation()">平移</button>
        <button onclick="getpath()">获得围栏路径</button>
        <button onclick="remove()">移除围栏</button>
    </div>
</body>

</html>
<script>
    var inmap = new inMap.Map({
        id: 'allmap',
        // skin: "Blueness",
        center: [105.403119, 38.028658],
        zoom: {
            value: 5,
            show: true,
            max: 18,
            min: 5
        },
    });
    var overlay  = new inMap.PolygonEditorOverlay({
        style: {
            isEdit: true,
            point: {
                normal: {
                    backgroundColor: "rgba(93,158,247,0.7)", // 填充颜色
                    size: 6, // 半径
                },
                mouseOver: {
                    backgroundColor: "rgba(93,158,247,1)",
                    borderColor: "rgba(93,158,247,1)",
                    borderWidth: 1
                },
                selected: {
                    borderWidth: 1,
                    backgroundColor: "rgba(184,0,0,1)",
                }

            },
            virtualPoint: {
                normal: {
                    backgroundColor: 'rgba(0, 0, 0, 0)',
                    borderWidth: 1,
                    borderColor: "rgba(0,131,238, 1)",
                    size: 6,
                },
                mouseOver: {
                    backgroundColor: 'rgba(0, 0, 0, 0)',
                    borderWidth: 2
                },

            },
            polygon: {
                normal: {
                    borderWidth: 1.5,
                    backgroundColor: "rgba(0,184,255,0.3)"
                }
            }
        },
        data: null,
    });
    inmap.add(overlay);

    function removeOverlay() {
        if (overlay) {
            inmap.remove(overlay);
        }
    }

    function addOverlay() {
        overlay.create();
    }

    function addEditorOverLay() {
        overlay.setPath(data);
    }

    function openEdit() {
        overlay.enableEditing();
    }

    function closeEdit() {
        overlay.disableEditing();
    }

    function translation() {
        overlay.translationPixel(20, 20);
    }

    function getpath() {
        let data = JSON.stringify(overlay.getPath(), null, 2);
        console.log(data);
        alert(data);
    }

    this.addEditorOverLay();

    function remove() {
        inmap.remove(overlay);
    }
</script>